package com.jcli.fx3u;

import com.jcli.HslCommunication.Core.Types.OperateResultExOne;
import com.jcli.HslCommunication.Profinet.Melsec.MelsecA1ENet;

import java.util.Date;

/**
 * @author ljc
 * @version 1.0
 * @date 2023/11/10 20:44
 */
public class Demo1110 {
    public static void main(String[] args) {
        // 创建Melsec A1E客户端对象并与PLC通信
        MelsecA1ENet melsec_net = new MelsecA1ENet("192.168.1.11", 3000);
        melsec_net.SetPersistentConnection();
        System.out.println("连接成功");
        Date date = new Date();
        System.out.println(date.toString());
       long startTime = System.currentTimeMillis();
        OperateResultExOne<int[]> read = melsec_net.ReadInt32("D1", (short) 30);
        if (read.IsSuccess) {
            for (int i = 0; i < 30; i++) {
                int j = read.Content[i];
                System.out.print(j + " ");
            }
        } else {
            System.out.println("读取失败");
        }
        System.out.println();
        System.out.println(date.toString());
        OperateResultExOne<int[]> read1 = melsec_net.ReadInt32("D31", (short) 30);
        if (read1.IsSuccess) {
            for (int i = 0; i < 30; i++) {
                int j = read1.Content[i];
                System.out.print(j + " ");
            }
        } else {
            System.out.println("读取失败");
        }
        System.out.println();
        System.out.println(date.toString());
        OperateResultExOne<int[]> read2 = melsec_net.ReadInt32("D61", (short) 30);
        if (read2.IsSuccess) {
            for (int i = 0; i < 30; i++) {
                int j = read2.Content[i];
                System.out.print(j + " ");
            }
        } else {
            System.out.println("读取失败");
        }
        System.out.println();
        System.out.println(date.toString());
        OperateResultExOne<int[]> read3 = melsec_net.ReadInt32("D91", (short) 30);
        if (read3.IsSuccess) {
            for (int i = 0; i < 30; i++) {
                int j = read3.Content[i];
                System.out.print(j + " ");
            }
        } else {
            System.out.println("读取失败");
        }
        System.out.println();
        System.out.println(date.toString());
        OperateResultExOne<int[]> read4 = melsec_net.ReadInt32("D121", (short) 30);
        if (read4.IsSuccess) {
            for (int i = 0; i < 30; i++) {
                int j = read4.Content[i];
                System.out.print(j + " ");
            }
        } else {
            System.out.println("读取失败");
        }
        System.out.println();
        System.out.println(date.toString());

        OperateResultExOne<int []> read5 = melsec_net.ReadInt32("D151", (short) 30);
        if (read5.IsSuccess){
            for (int i = 0; i < 30; i++) {
                int j = read5.Content[i];
                System.out.print(j+" ");
            }}
        else {
            System.out.println("读取失败");
        }
        System.out.println();
        System.out.println(date.toString());

        OperateResultExOne<int []> read6 = melsec_net.ReadInt32("D181", (short) 30);
        if (read6.IsSuccess){
            for (int i = 0; i < 30; i++) {
                int j = read6.Content[i];
                System.out.print(j+" ");
            }}
        else {
            System.out.println("读取失败");
        }
        System.out.println();
        System.out.println(date.toString());

        OperateResultExOne<int []> read7 = melsec_net.ReadInt32("D211", (short) 30);
        if (read7.IsSuccess){
            for (int i = 0; i < 30; i++) {
                int j = read.Content[i];
                System.out.print(j+" ");
            }}
        else {
            System.out.println("读取失败");
        }
        System.out.println();
        System.out.println(date.toString());


        Date endDate = new Date();
        long endTime = System.currentTimeMillis();
        System.out.println("读取耗时："+(endTime-startTime)+"ms");
    }
}
